<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>Android 混淆 | 张芃</title><meta name="keywords" content="Android"><meta name="author" content="张芃"><meta name="copyright" content="张芃"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Android 混淆1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991">
<meta property="og:type" content="article">
<meta property="og:title" content="Android 混淆">
<meta property="og:url" content="https://zhangpeng-1304089575.cos-website.ap-shanghai.myqcloud.com/2020/04/09/%E5%A4%A7%E5%89%8D%E7%AB%AF/Android/Android%20%E6%B7%B7%E6%B7%86/index.html">
<meta property="og:site_name" content="张芃">
<meta property="og:description" content="Android 混淆1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://zhangpeng-1304089575.cos-website.ap-shanghai.myqcloud.com/img/android.png">
<meta property="article:published_time" content="2020-04-08T16:00:00.000Z">
<meta property="article:modified_time" content="2022-02-11T06:23:11.339Z">
<meta property="article:author" content="张芃">
<meta property="article:tag" content="Android">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://zhangpeng-1304089575.cos-website.ap-shanghai.myqcloud.com/img/android.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://zhangpeng-1304089575.cos-website.ap-shanghai.myqcloud.com/2020/04/09/%E5%A4%A7%E5%89%8D%E7%AB%AF/Android/Android%20%E6%B7%B7%E6%B7%86/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Android 混淆',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-02-11 14:23:11'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.0.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">23</div></a></div><div class="data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">11</div></a></div><div class="data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">10</div></a></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/android.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">张芃</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Android 混淆</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-04-08T16:00:00.000Z" title="发表于 2020-04-09 00:00:00">2020-04-09</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-02-11T06:23:11.339Z" title="更新于 2022-02-11 14:23:11">2022-02-11</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%A4%A7%E5%89%8D%E7%AB%AF/">大前端</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%A4%A7%E5%89%8D%E7%AB%AF/Android/">Android</a></span></div><div class="meta-secondline"></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Android-混淆"><a href="#Android-混淆" class="headerlink" title="Android 混淆"></a>Android 混淆</h1><figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#############################################</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># 对于一些基本指令的添加</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment">#############################################</span></span><br><span class="line"><span class="comment"># 代码混淆压缩比，在0~7之间，默认为5，一般不做修改</span></span><br><span class="line"><span class="attr">-optimizationpasses</span> <span class="string">5</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 混合时不使用大小写混合，混合后的类名为小写</span></span><br><span class="line"><span class="attr">-dontusemixedcaseclassnames</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 指定不去忽略非公共库的类</span></span><br><span class="line"><span class="attr">-dontskipnonpubliclibraryclasses</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 这句话能够使我们的项目混淆后产生映射文件</span></span><br><span class="line"><span class="comment"># 包含有类名-&gt;混淆后类名的映射关系</span></span><br><span class="line"><span class="attr">-verbose</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 指定不去忽略非公共库的类成员</span></span><br><span class="line"><span class="attr">-dontskipnonpubliclibraryclassmembers</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 不做预校验，preverify是proguard的四个步骤之一，Android不需要preverify，去掉这一步能够加快混淆速度。</span></span><br><span class="line"><span class="attr">-dontpreverify</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 保留Annotation不混淆</span></span><br><span class="line"><span class="attr">-keepattributes</span> <span class="string">*Annotation*,InnerClasses</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 避免混淆泛型</span></span><br><span class="line"><span class="attr">-keepattributes</span> <span class="string">Signature</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 抛出异常时保留代码行号</span></span><br><span class="line"><span class="attr">-keepattributes</span> <span class="string">SourceFile,LineNumberTable</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 指定混淆是采用的算法，后面的参数是一个过滤器</span></span><br><span class="line"><span class="comment"># 这个过滤器是谷歌推荐的算法，一般不做更改</span></span><br><span class="line"><span class="attr">-optimizations</span> <span class="string">!code/simplification/cast,!field/*,!class/merging/*</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">#############################################</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># Android开发中一些需要保留的公共部分</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment">#############################################</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 保留我们使用的四大组件，自定义的Application等等这些类不被混淆</span></span><br><span class="line"><span class="comment"># 因为这些子类都有可能被外部调用</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * extends android.app.Activity</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * extends android.app.Appliction</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * extends android.app.Service</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * extends android.content.BroadcastReceiver</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * extends android.content.ContentProvider</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * extends android.app.backup.BackupAgentHelper</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * extends android.preference.Preference</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * extends android.view.View</span></span><br><span class="line"><span class="comment">#-keep public class com.android.vending.licensing.ILicensingService</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 保留support下的所有类及其内部类</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">class android.support.** &#123;*;&#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 保留继承的</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * extends android.support.v4.**</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * extends android.support.v7.**</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * extends android.support.annotation.**</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">#androidx包使用混淆</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">class com.google.android.material.** &#123;*;&#125;</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">class androidx.** &#123;*;&#125;</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * extends androidx.**</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">interface androidx.** &#123;*;&#125;</span></span><br><span class="line"><span class="attr">-dontwarn</span> <span class="string">com.google.android.material.**</span></span><br><span class="line"><span class="attr">-dontnote</span> <span class="string">com.google.android.material.**</span></span><br><span class="line"><span class="attr">-dontwarn</span> <span class="string">androidx.**</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 保留R下面的资源</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">class **.R$* &#123;*;&#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 保留本地native方法不被混淆</span></span><br><span class="line"><span class="attr">-keepclasseswithmembernames</span> <span class="string">class * &#123;</span></span><br><span class="line">    <span class="attr">native</span> <span class="string">&lt;methods&gt;;</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 保留在Activity中的方法参数是view的方法，</span></span><br><span class="line"><span class="comment"># 这样以来我们在layout中写的onClick就不会被影响</span></span><br><span class="line"><span class="attr">-keepclassmembers</span> <span class="string">class * extends android.app.Activity&#123;</span></span><br><span class="line">    <span class="attr">public</span> <span class="string">void *(android.view.View);</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 保留枚举类不被混淆</span></span><br><span class="line"><span class="attr">-keepclassmembers</span> <span class="string">enum * &#123;</span></span><br><span class="line">    <span class="attr">public</span> <span class="string">static **[] values();</span></span><br><span class="line">    <span class="attr">public</span> <span class="string">static ** valueOf(java.lang.String);</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 保留我们自定义控件（继承自View）不被混淆</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * extends android.view.View&#123;</span></span><br><span class="line">    <span class="attr">***</span> <span class="string">get*();</span></span><br><span class="line">    <span class="attr">void</span> <span class="string">set*(***);</span></span><br><span class="line">    <span class="attr">public</span> <span class="string">&lt;init&gt;(android.content.Context);</span></span><br><span class="line">    <span class="attr">public</span> <span class="string">&lt;init&gt;(android.content.Context, android.util.AttributeSet);</span></span><br><span class="line">    <span class="attr">public</span> <span class="string">&lt;init&gt;(android.content.Context, android.util.AttributeSet, int);</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 保留Parcelable序列化类不被混淆</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">class * implements android.os.Parcelable &#123;</span></span><br><span class="line">    <span class="attr">public</span> <span class="string">static final android.os.Parcelable$Creator *;</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 保留Serializable序列化的类不被混淆</span></span><br><span class="line"><span class="attr">-keepclassmembers</span> <span class="string">class * implements java.io.Serializable &#123;</span></span><br><span class="line">    <span class="attr">static</span> <span class="string">final long serialVersionUID;</span></span><br><span class="line">    <span class="attr">private</span> <span class="string">static final java.io.ObjectStreamField[] serialPersistentFields;</span></span><br><span class="line"><span class="comment">    !static !transient &lt;fields&gt;;</span></span><br><span class="line"><span class="comment">    !private &lt;fields&gt;;</span></span><br><span class="line"><span class="comment">    !private &lt;methods&gt;;</span></span><br><span class="line">    <span class="attr">private</span> <span class="string">void writeObject(java.io.ObjectOutputStream);</span></span><br><span class="line">    <span class="attr">private</span> <span class="string">void readObject(java.io.ObjectInputStream);</span></span><br><span class="line">    <span class="attr">java.lang.Object</span> <span class="string">writeReplace();</span></span><br><span class="line">    <span class="attr">java.lang.Object</span> <span class="string">readResolve();</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 对于带有回调函数的onXXEvent、**On*Listener的，不能被混淆</span></span><br><span class="line"><span class="attr">-keepclassmembers</span> <span class="string">class * &#123;</span></span><br><span class="line">    <span class="attr">void</span> <span class="string">*(**On*Event);</span></span><br><span class="line">    <span class="attr">void</span> <span class="string">*(**On*Listener);</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># webView处理，项目中没有使用到webView忽略即可</span></span><br><span class="line"><span class="attr">-keepclassmembers</span> <span class="string">class fqcn.of.javascript.interface.for.webview &#123;</span></span><br><span class="line">    <span class="attr">public</span> <span class="string">*;</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="attr">-keepclassmembers</span> <span class="string">class * extends android.webkit.webViewClient &#123;</span></span><br><span class="line">    <span class="attr">public</span> <span class="string">void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap);</span></span><br><span class="line">    <span class="attr">public</span> <span class="string">boolean *(android.webkit.WebView, java.lang.String);</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="attr">-keepclassmembers</span> <span class="string">class * extends android.webkit.webViewClient &#123;</span></span><br><span class="line">    <span class="attr">public</span> <span class="string">void *(android.webkit.webView, jav.lang.String);</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">########################################################################默认配置</span></span><br><span class="line"><span class="comment">#ARouter混淆</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class com.alibaba.android.arouter.routes.**&#123;*;&#125;</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">class * implements com.alibaba.android.arouter.facade.template.ISyringe&#123;*;&#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 如果使用了 byType 的方式获取 Service，需添加下面规则，保护接口</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">interface * implements com.alibaba.android.arouter.facade.template.IProvider</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 如果使用了 单类注入，即不定义接口实现 IProvider，需添加下面规则，保护实现</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">class * implements com.alibaba.android.arouter.facade.template.IProvider</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># Glide</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class * implements com.bumptech.glide.module.GlideModule</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** &#123;</span></span><br><span class="line">  <span class="attr">**[]</span> <span class="string">$VALUES;</span></span><br><span class="line">  <span class="attr">public</span> <span class="string">*;</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="comment"># Gson</span></span><br><span class="line"><span class="attr">-keepattributes</span> <span class="string">Signature</span></span><br><span class="line"><span class="attr">-keepattributes</span> <span class="string">*Annotation*</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">class sun.misc.Unsafe &#123; *; &#125;</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">class com.google.gson.stream.** &#123; *; &#125;</span></span><br><span class="line"><span class="comment"># 使用Gson时需要配置Gson的解析对象及变量都不混淆。不然Gson会找不到变量。</span></span><br><span class="line"><span class="comment"># 将下面替换成自己的实体类</span></span><br><span class="line"><span class="comment">#-keep class com.example.bean.** &#123; *; &#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># OkHttp</span></span><br><span class="line"><span class="attr">-dontwarn</span> <span class="string">okio.**</span></span><br><span class="line"><span class="attr">-dontwarn</span> <span class="string">okhttp3.**</span></span><br><span class="line"><span class="attr">-dontwarn</span> <span class="string">javax.annotation.Nullable</span></span><br><span class="line"><span class="attr">-dontwarn</span> <span class="string">javax.annotation.ParametersAreNonnullByDefault</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># Okio</span></span><br><span class="line"><span class="attr">-dontwarn</span> <span class="string">com.squareup.**</span></span><br><span class="line"><span class="attr">-dontwarn</span> <span class="string">okio.**</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class org.codehaus.* &#123; *; &#125;</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class java.nio.* &#123; *; &#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># Retrofit</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">class retrofit2.** &#123; *; &#125;</span></span><br><span class="line"><span class="attr">-dontwarn</span> <span class="string">retrofit2.**</span></span><br><span class="line"><span class="attr">-keepattributes</span> <span class="string">Signature</span></span><br><span class="line"><span class="attr">-keepattributes</span> <span class="string">Exceptions</span></span><br><span class="line"><span class="attr">-dontwarn</span> <span class="string">okio.**</span></span><br><span class="line"><span class="attr">-dontwarn</span> <span class="string">javax.annotation.**</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># XLog</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">class com.tencent.mars.** &#123; *; &#125;</span></span><br><span class="line"><span class="attr">-keepclassmembers</span> <span class="string">class com.tencent.mars.** &#123; *; &#125;</span></span><br><span class="line"><span class="attr">-dontwarn</span> <span class="string">com.tencent.mars.**</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># xUtils3.0</span></span><br><span class="line"><span class="attr">-keepattributes</span> <span class="string">Signature,Annotation</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public class org.xutils.** &#123;</span></span><br><span class="line"><span class="attr">public</span> <span class="string">protected *;</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="attr">-keep</span> <span class="string">public interface org.xutils.** &#123;</span></span><br><span class="line"><span class="attr">public</span> <span class="string">protected *;</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="attr">-keepclassmembers</span> <span class="string">class * extends org.xutils.** &#123;</span></span><br><span class="line"><span class="attr">public</span> <span class="string">protected *;</span></span><br><span class="line"><span class="attr">&#125;</span></span><br><span class="line"><span class="attr">-keepclassmembers</span> <span class="string">@org.xutils.db.annotation.* class * &#123;*;&#125;</span></span><br><span class="line"><span class="attr">-keepclassmembers</span> <span class="string">@org.xutils.http.annotation. class * &#123;*;&#125;</span></span><br><span class="line"><span class="attr">-keepclassmembers</span> <span class="string">class * &#123;*;&#125;</span></span><br></pre></td></tr></table></figure></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">张芃</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://zhangpeng-1304089575.cos-website.ap-shanghai.myqcloud.com/2020/04/09/%E5%A4%A7%E5%89%8D%E7%AB%AF/Android/Android%20%E6%B7%B7%E6%B7%86/">https://zhangpeng-1304089575.cos-website.ap-shanghai.myqcloud.com/2020/04/09/%E5%A4%A7%E5%89%8D%E7%AB%AF/Android/Android%20%E6%B7%B7%E6%B7%86/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://zhangpeng-1304089575.cos-website.ap-shanghai.myqcloud.com" target="_blank">张芃</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Android/">Android</a></div><div class="post_share"><div class="social-share" data-image="/img/android.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2020/04/26/%E5%A4%A7%E5%89%8D%E7%AB%AF/Android/Android%E7%AC%94%E8%AE%B0%E4%B9%8B%E4%BD%BF%E7%94%A8CMake%E8%BF%9B%E8%A1%8CJNI%E5%BC%80%E5%8F%91/"><img class="prev-cover" src="/img/android.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">使用CMake进行JNI开发</div></div></a></div><div class="next-post pull-right"><a href="/2020/03/18/%E5%A4%A7%E5%89%8D%E7%AB%AF/Android/Gson%20%E8%BF%87%E6%BB%A4%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E5%AD%97%E6%AE%B5/"><img class="next-cover" src="/img/android.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Gson 过滤反序列化字段</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2019/09/25/Java/%E6%9E%9A%E4%B8%BE%E5%9E%8B%20%E5%8D%95%E4%BE%8B%E6%A8%A1%E5%BC%8F/" title="枚举型 单例模式"><img class="cover" src="/img/java.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-09-25</div><div class="title">枚举型 单例模式</div></div></a></div><div><a href="/2018/08/07/%E5%A4%A7%E5%89%8D%E7%AB%AF/Android/Android%20%20drawable%E4%B8%AD%E8%BE%B9%E6%A1%86%E6%A0%B7%E5%BC%8F/" title="Android drawable中边框样式"><img class="cover" src="/img/android.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2018-08-07</div><div class="title">Android drawable中边框样式</div></div></a></div><div><a href="/2020/01/19/%E5%A4%A7%E5%89%8D%E7%AB%AF/Android/Android%20handler+WeakReference%E5%BC%B1%E5%BC%95%E7%94%A8/" title="Android handler+WeakReference弱引用"><img class="cover" src="/img/android.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-01-19</div><div class="title">Android handler+WeakReference弱引用</div></div></a></div><div><a href="/2020/11/09/%E5%A4%A7%E5%89%8D%E7%AB%AF/Android/Android%20%E5%BC%80%E6%BA%90/" title="Android 开源 部分不常用的收集"><img class="cover" src="/img/android.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-11-09</div><div class="title">Android 开源 部分不常用的收集</div></div></a></div><div><a href="/2019/12/20/%E5%A4%A7%E5%89%8D%E7%AB%AF/Android/Android%E5%9C%A8TextView%E4%B8%AD%E8%AE%BE%E7%BD%AE%E9%83%A8%E5%88%86%E6%96%87%E5%AD%97%E5%8F%AF%E7%82%B9%E5%87%BB/" title="Android在TextView中设置部分文字可点击"><img class="cover" src="/img/android.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-12-20</div><div class="title">Android在TextView中设置部分文字可点击</div></div></a></div><div><a href="/2019/07/05/%E5%A4%A7%E5%89%8D%E7%AB%AF/Android/Android%20%E7%8A%B6%E6%80%81%E6%A0%8F%E9%80%8F%E6%98%8E%20%E4%B8%94%E5%8F%AF%E4%BB%A5%E7%99%BD%E5%BA%95%E9%BB%91%E5%AD%97/" title="Android 状态栏透明 且可以白底黑字"><img class="cover" src="/img/android.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-07-05</div><div class="title">Android 状态栏透明 且可以白底黑字</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">张芃</div><div class="author-info__description"></div></div><div class="card-info-data is-center"><div class="card-info-data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">23</div></a></div><div class="card-info-data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">11</div></a></div><div class="card-info-data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">10</div></a></div></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/zhangpeng_git"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Android-%E6%B7%B7%E6%B7%86"><span class="toc-number">1.</span> <span class="toc-text">Android 混淆</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/02/11/%E5%A4%A7%E5%89%8D%E7%AB%AF/Vue/Vue%E4%B8%ADkey%E7%9A%84%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86/" title="Vue中key的工作原理"><img src="/img/vue.svg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Vue中key的工作原理"/></a><div class="content"><a class="title" href="/2022/02/11/%E5%A4%A7%E5%89%8D%E7%AB%AF/Vue/Vue%E4%B8%ADkey%E7%9A%84%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86/" title="Vue中key的工作原理">Vue中key的工作原理</a><time datetime="2022-02-10T16:00:00.000Z" title="发表于 2022-02-11 00:00:00">2022-02-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/02/11/%E5%A4%A7%E5%89%8D%E7%AB%AF/Vue/Vue%E5%87%BD%E6%95%B0%E5%BC%8F%E7%BB%84%E4%BB%B6/" title="Vue函数式组件"><img src="/img/vue.svg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Vue函数式组件"/></a><div class="content"><a class="title" href="/2022/02/11/%E5%A4%A7%E5%89%8D%E7%AB%AF/Vue/Vue%E5%87%BD%E6%95%B0%E5%BC%8F%E7%BB%84%E4%BB%B6/" title="Vue函数式组件">Vue函数式组件</a><time datetime="2022-02-10T16:00:00.000Z" title="发表于 2022-02-11 00:00:00">2022-02-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/02/11/%E5%A4%A7%E5%89%8D%E7%AB%AF/Vue/Vue%E7%89%B9%E6%80%A7%E6%80%BB%E7%BB%93/" title="Vue特性总结"><img src="/img/vue.svg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Vue特性总结"/></a><div class="content"><a class="title" href="/2022/02/11/%E5%A4%A7%E5%89%8D%E7%AB%AF/Vue/Vue%E7%89%B9%E6%80%A7%E6%80%BB%E7%BB%93/" title="Vue特性总结">Vue特性总结</a><time datetime="2022-02-10T16:00:00.000Z" title="发表于 2022-02-11 00:00:00">2022-02-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2022/02/11/%E5%A4%A7%E5%89%8D%E7%AB%AF/Vue/ElementUI/%E8%87%AA%E5%AE%9A%E4%B9%89table/" title="自定义el-table">自定义el-table</a><time datetime="2022-02-10T16:00:00.000Z" title="发表于 2022-02-11 00:00:00">2022-02-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/02/10/%E5%A4%A7%E5%89%8D%E7%AB%AF/CSS/%E8%A7%A3%E5%86%B3node-sass%E7%9A%84%E5%AE%89%E8%A3%85%E9%97%AE%E9%A2%98/" title="解决node-sass的安装问题"><img src="" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="解决node-sass的安装问题"/></a><div class="content"><a class="title" href="/2022/02/10/%E5%A4%A7%E5%89%8D%E7%AB%AF/CSS/%E8%A7%A3%E5%86%B3node-sass%E7%9A%84%E5%AE%89%E8%A3%85%E9%97%AE%E9%A2%98/" title="解决node-sass的安装问题">解决node-sass的安装问题</a><time datetime="2022-02-09T16:00:00.000Z" title="发表于 2022-02-10 00:00:00">2022-02-10</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By 张芃</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><div class="js-pjax"></div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script></div></body></html>